﻿using System;

namespace Miao
{
    public readonly struct Range : IRange<float>, IEquatable<Range>
    {
        public float min { get; }
        public float max { get; }

        public Range(float min, float max)
        {
            this.min = min;
            this.max = max;
        }

        public bool Contains(float value)
        {
            return min <= value && value <= max;
        }
        public bool Equals(Range other)
        {
            return min == other.min && max == other.max;
        }

        public override string ToString()
        {
            return $"({min}, {max})";
        }
        public override bool Equals(object obj)
        {
            return obj is Range range && Equals(range);
        }
        public override int GetHashCode()
        {
            return HashCode.Combine(min, max);
        }

        public static Range operator /(Range self, float value)
        {
            return new Range(self.min / value, self.max / value);
        }
        public static Range operator *(Range self, float value)
        {
            return new Range(self.min * value, self.max * value);
        }
        public static bool operator ==(Range left, Range right)
        {
            return left.Equals(right);
        }
        public static bool operator !=(Range left, Range right)
        {
            return !(left == right);
        }
    }
}